Adds authentication information to the client, use the static Self to authenticate as the currently logged on Windows user. This overload allows you to specify the privacy level and authentication types to try. Normally these default to RPC_C_PROTECT_LEVEL_PKT_PRIVACY, and both RPC_C_AUTHN_GSS_NEGOTIATE or RPC_C_AUTHN_WINNT if that fails. If credentials is null, or is the Anonymous user, RPC_C_PROTECT_LEVEL_DEFAULT and RPC_C_AUTHN_NONE are used instead.
Syntax
Parameters
- serverPrincipalName
- credentials
- level
- authTypes
Example
RpcLibrary/RpcLibrary.Test/TestServerApi.cs
C# | Copy Code |
---|
Guid iid = Guid.NewGuid();
using (RpcServerApi server = new RpcServerApi(iid))
{
server.AddProtocol(RpcProtseq.ncalrpc, "lrpctest", 5);
server.AddAuthentication(RpcAuthentication.RPC_C_AUTHN_WINNT);
server.StartListening();
RpcServerApi.RpcExecuteHandler handler =
delegate(IRpcClientInfo client, byte[] arg)
{ return arg; };
using (RpcClientApi client = new RpcClientApi(iid, RpcProtseq.ncalrpc, null, "lrpctest"))
{
client.AuthenticateAs(null, RpcClientApi.Self, RpcProtectionLevel.RPC_C_PROTECT_LEVEL_PKT_PRIVACY, RpcAuthentication.RPC_C_AUTHN_WINNT);
server.OnExecute += handler;
client.Execute(new byte[0]);
server.OnExecute -= handler;
try
{
client.Execute(new byte[0]);
Assert.Fail();
}
catch (RpcException)
{ }
}
} |
VB.NET | Copy Code |
---|
Dim iid As Guid = Guid.NewGuid()
Using server As New RpcServerApi(iid)
server.AddProtocol(RpcProtseq.ncalrpc, "lrpctest", 5)
server.AddAuthentication(RpcAuthentication.RPC_C_AUTHN_WINNT)
server.StartListening()
Dim handler As RpcServerApi.RpcExecuteHandler = Function(client As IRpcClientInfo, arg As Byte()) Do
Return arg
End Function
Using client As New RpcClientApi(iid, RpcProtseq.ncalrpc, Nothing, "lrpctest")
client.AuthenticateAs(Nothing, RpcClientApi.Self, RpcProtectionLevel.RPC_C_PROTECT_LEVEL_PKT_PRIVACY, RpcAuthentication.RPC_C_AUTHN_WINNT)
server.OnExecute += handler
client.Execute(New Byte(0) {})
server.OnExecute -= handler
Try
client.Execute(New Byte(0) {})
Assert.Fail()
Catch generatedExceptionName As RpcException
End Try
End Using
End Using |
Requirements
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7
See Also